<template>
  <button class="toggle" @click="change">{{ val }}</button>
  <div class="clock-container">
    <div class="clock">
      <div class="needle hour"></div>
      <div class="needle minute"></div>
      <div class="needle second"></div>
      <div class="center-point"></div>
    </div>
    <div class="time">{{ date }}</div>
    <div class="date">{{ day }}</div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import {days,months} from '../config/index'
let val = ref('Dark mode')
const date = ref('9:47 PM');
const day = ref('Thursday,Mar');
const getTime = () => {
  const dates = new Date;
  let h = dates.getHours();
  let m = dates.getMinutes();
  const noon = h > 12 ? 'PM' : 'AM'
  h = h <= 12 ? h : h - 12;
  m = m < 10 ? '0' + m : m;
  // console.log(m);
  date.value = (`${h}:${m} ${noon}`);
};
getTime();
const timer = setInterval(() => {
  getTime();
  getDay()
}, 1000);
const getDay = () =>{
  const dates = new Date;
  let d = dates.getDay();
  let m = dates.getMonth(); 
  day.value = `${days[d]},${months[m]}`
}
getDay()
const change = () => {
  if (val.value == 'Dark mode') {
    val.value = 'Light mode'
  } else {
    val.value = 'Dark mode'
  }
}

</script>

<style>
* {
  border-sizing: border-box;
}

:root {
  --primary-color: #000;
  --secondary-color: #fff;
}

html {
  transition: all 0.5s ease-in;
}

html.dark {
  --primary-color: #fff;
  --secondary-color: #333;
}

html.dark {
  background-color: #111;
  color: var(--primary-color);
}

body,
#app,
.app {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  overflow: hidden;
  margin: 0;
}

.toggle {
  cursor: pointer;
  background-color: var(--primary-color);
  color: var(--secondary-color);
  border: 0;
  border-radius: 4px;
  padding: 8px 12px;
  position: absolute;
  top: 100px;
}

.toggle:focus {
  outline: none;
}

.clock-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.clock {
  position: relative;
  width: 200px;
  height: 200px;
}

.needle {
  background-color: var(--primary-color);
  position: absolute;
  top: 50%;
  left: 50%;
  height: 65px;
  width: 3px;
  transform-origin: bottom center;
  transition: all 0.5s ease-in;
}

.needle.hour {
  transform: translate(-50%, -100%) rotate(0deg);
}

.needle.minute {
  transform: translate(-50%, -100%) rotate(0deg);
  height: 100px;
}

.needle.second {
  transform: translate(-50%, -100%) rotate(0deg);
  height: 100px;
  background-color: #e74c3c;
}

.center-point {
  background-color: #e74c3c;
  width: 10px;
  height: 10px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.center-point::after {
  content: '';
  background-color: var(--primary-color);
  width: 5px;
  height: 5px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.time {
  font-size: 60px;
}

.date {
  color: #aaa;
  font-size: 14px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.date .circle {
  background-color: var(--primary-color);
  color: var(--secondary-color);
  border-radius: 50%;
  height: 18px;
  width: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 18px;
  transition: all 0.5s ease-in;
  font-size: 12px;
}</style>